set maxvar 9000

log using "$rootpath/log/TABLE_4_COL2AND4SL.log", replace
use "$rootpath/processed_data/Estimation_Data.dta", clear
drop if key_estimation_sample==0
  
replace naics=naics*1000 if naics<1000
replace naics=naics*100 if naics<10000
replace naics=naics*10 if naics<100000

gen n3=floor(naics/1000)

egen test1000=nvals(treatXpost), by(n3)
replace n3=929 if test1000<5

gen n3fe=year*1000+n3

tabulate n3fe, gen(n3fe_)
gen codefe=0 if year<2015
replace codefe=year+avg_old_code_prob if year>2014
tabulate codefe, gen(codefe_)
gen treatXalt=0
replace treatXalt=1 if avg_old_code_prob>0&year>2014
egen rankgroup = group(avg_old_code_prob)
//Note, the choice for using the did_multiplegt_dyn to estimate the 
//Weighted average of the switchers slopes estimator stems from the July 1 2023 version 
//of de Chaisemartin, D’Haultfoeuille, Pasquier, and Vazquez-Bare paper 
//"Difference-in-Differences Estimators for Treatments Continuously Distributed at Every Period"
//stems the statement "estimators can be computed by the did_multiplegt_dyn Stata package"
//on page 4 along with the statement delta r "can be computed by the did_multiplegt Stata command"
//on page 16. Specifically, we believe the use did_multiplegt_dyn with only one period (non-dynamic) effects
//is equivalent to the origina did_multiplegt command following the discussions in "Comparing the did_multiplegt and did_multiplegt_dyn Stata commands"
//January 2024 article by de Chaisemartin and co-authors which indicates that "When completed, did_multiplegt_dyn will supersede did_multiplegt"
//and also "The two commands do not output different event-study and placebo effects when applied to a bal- anced panel of groups"
//Finally, the version of the "did_multiplegt_dyn" for this analysis is dated  February 15, 2024.

did_multiplegt_dyn log_damage55 facility_id year treatXpost, normalize controls(n3fe_*)   effects(1) placebo(0) cluster(state_number) 

did_multiplegt_dyn log_emissions4 facility_id year treatXpost, normalize controls(n3fe_*)   effects(1) placebo(0) cluster(state_number) 
log close
